const app = require('express')();
const http = require('http').createServer(app);
const io = require('socket.io')(http);


app.get('/', function(req, res){
    res.send('<h1>Hello world</h1>');
});

io.on('connection', function(socket){
    console.log('a user connected');
    socket.on('disconnect', function(){
        console.log('user disconnected');
    });

    socket.on('login', (msg) =>{
        console.log(msg, '11111111111111')
    })

    socket.on('sendMessage', function(msg){
        console.log('message: ' + msg);
        // socket.emit('message', { my: 'data' });
        socket.broadcast.emit('message', {my:'data'});
    });
});


http.listen(3000, function(){
    console.log('http://localhost:3000  listening on *:3000');
});
